在開發 Magento 的購物商城的時候,常常會需要產生一些測試用的假資料,一方面可以得知開發的頁面是否會跑版,也可以測試自己伺服器的效能是否足夠,是否需要使用更進階的伺服器等級。
而 Magento 內建其實就有這種方便好用的功能,不但能夠產生顧客、商品、商店、類別等資料,而且還能夠依照不同等級的商店,產生出不同數量,是不是很方面呢? 工具所產生出來的資料大小可區分為:小( small )、中型( medium )、大型( large )、超大型( extra_large )等四種,我們可以從下表中知道他們分別產生出多少資料。
小 Small | 中型 Medium | 大型 Large | 超大型 Extra large | |
---|---|---|---|---|
websites | 1 | 1 | 3 | 5 |
store_groups | 1 | 2 | 3 | 5 |
store_views | 1 | 2 | 3 | 5 |
simple_products | 800 | 16,000 | 400,000 | 800,000 |
configurable_products | 50 | 1,000 | 25,000 | 50,000 |
categories | 30 | 300 | 1,000 | 3,000 |
categories_nesting_level | 3 | 3 | 3 | 6 |
customers | 20 | 200 | 2,000 | 5,000 |
orders | 80 | 1,600 | 40,000 | 80,000 |
執行環境
- 作業系統:Linux Ubuntu16.04
- Magento 版本:Magento 2.2
- PHP 版本:7.0.22
執行
利用 Magento 原生的指令如下:
$bin/magento setup:perf:generate-fixtures {path to file}
最後面是填入定義檔案名稱,而 Magento 的定義檔已經幫我們寫好了,路徑為
/setup/performance-toolkit/profiles/ce/small.xml
執行結果如下圖,表示執行正確,執行命令後,系統會自動做一次 Reindex ,故下面產生的結果屬於正常現象。
額外配置
除了 Magento 預設的配置之外,我們也可以依照自己實際的需求來自定義設定檔,以下摘錄幾個較為常用的設定。
- 簡易型產品 Simple Product
產生 Simple Product ,產品依照預設的Attribute set
做設定,中間的{ int }
數值為要產生多少數量的 Simple product。{int}
- 顧客 Customers
產生假顧客,每一個帳戶除了用戶Email
之外,都會產生一樣的資料。中間的{ int }
數值為要產生多少數量的 Customer。{int}
- 商店 Store View
產生 Store View。中間的 {int} 數值為要產生多少數量的 Store View。第二行的參數 {0|1} ,填寫 1 則表示 All Strore View ,填寫 0 表示所有商店皆有唯一的 root category。{int} {0|1}